﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：
    //

    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Hospitals.Procurement
{
    public partial class HospitalLoginPriceGoodsYes:BasePage
    {

        public int i = 1;
        IBLL_HospitalLoginPriceGoods ih = Factory.BLL_HospitalLoginPriceGoods();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
             SetBind();
            }
        }

        /// <summary>
        /// 绑定符合条件的采购明细
        /// </summary>
        private void SetBind()
        {
            int totalCount;
            IList<Model.View.HospitalLoginPriceGoods> purchaseOrderDetailList = ih.GetGoodsByWhere(GetCondition(), AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
           
            gvwNoConfirm.PageSize = AspNetPager1.PageSize;
            gvwNoConfirm.DataSource = purchaseOrderDetailList;
            gvwNoConfirm.DataBind();
        }
        /// <summary>
        /// 获取查询条件
        /// </summary>
        /// <returns></returns>
        private Model.Query.HospitalLoginPriceGoods GetCondition()
        {
                 Model.Query.HospitalLoginPriceGoods  where = new HZ.DrugTrade.Model.Query.HospitalLoginPriceGoods();
                where.GoodsID = txtGoodsID.Text.Trim();//流水号
                where.Outlookc = txtOutLook.Text.Trim(); //规格型号
                where.Unit = txtUnit.Text.Trim(); //单位
                where.CompanyName_SC = txtCompanyName_Sc.Text.Trim();//生产企业
                where.HospitalID = CurrentAccount.GetUser().UserID;//已填写
                where.Append = "  NVL(price,0)<>0  ";
                return where;
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            SetBind();
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }

 
        /// <summary>
        /// 导出2009-11-25
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            int totalCount;
            IList<Model.View.HospitalLoginPriceGoods> purchaseOrderDetailList = ih.GetGoodsByWhere(GetCondition(), 1, 0, out totalCount);
            System.Data.DataTable tb = HZ.Data.ModelConvert.GetDataTableFromModel(purchaseOrderDetailList);
            HZ.Excel.ExcelHelper.ExportDataForWeb(tb, gvwNoConfirm);
        }

        protected void gvwNoConfirm_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblgoodsID = e.Row.FindControl("lblGoodsID") as Label;//流水号
                Label lblState = e.Row.FindControl("lblstate") as Label;//产品提交状态
                Button btnSave=e.Row.FindControl("btn"+lblgoodsID.Text) as Button;//保存按钮
                HiddenField hidPrice = e.Row.FindControl("hidPrice") as HiddenField;//医疗机构价格
                HiddenField hidCount = e.Row.FindControl("hiCount") as HiddenField;//医疗机构购买数量
                //    Label lblshowPrice = e.Row.FindControl("showMessage") as Label;//流水号
                //10为填写购买价格
                e.Row.Cells[11].Text = "<input style=\"width:60px\"autocomplete=\"off\" type=\"text\" id=\"txtPrice" + lblgoodsID.Text + "\" value=\"" + hidPrice.Value + "\" />";
                //11为填写购买数量
                e.Row.Cells[12].Text = "<input style=\"width:60px\"autocomplete=\"off\" type=\"text\" id=\"countProduces" + lblgoodsID.Text + "\" value=\"" + hidCount.Value + "\" />";
                //12为保存数据
                //e.Row.Cells[12].Text = "<input type=\"button\" id=\"btn" + lblgoodsID.Text + "\" value=\"保存\" />";
                
                //e.Row.Cells[13].Text = "<input type=\"button\" id=\"btn" + lblgoodsID.Text + "\" disabled=\"disabled\"  value=\"<%# Eval(\"GoodsId\") %>\" onClick=\"SavePrice('txtPrice" + lblgoodsID.Text + "', '" + lblgoodsID.Text + "', '" + CurrentAccount.GetUser().UserID + "', 'countProduces" + lblgoodsID.Text + "')\"/>";

                if (lblState.Text == "已提交")
                {
                     e.Row.Cells[13].Text = "<input type=\"button\" id=\"btn" + lblgoodsID.Text + "\" value=\"保存\" />";
                    e.Row.Cells[13].Enabled=false;
                }
                else
                {
                    e.Row.Cells[13].Text = "<input type=\"button\" id=\"btn" + lblgoodsID.Text + "\" value=\"保存\" onClick=\"SavePrice('txtPrice" + lblgoodsID.Text + "', '" + lblgoodsID.Text + "', '" + CurrentAccount.GetUser().UserID + "', 'countProduces" + lblgoodsID.Text + "')\"/>";
                }
            }
        }

        /// <summary>
        ///  根据ID删除字段或者是根据ID批量删除
        ///  说明：根据ID删除在已经确定报价的表中移除
        ///        再次点击未确定报价时，显示出刚删除的那条数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected  void HzBtnDelete_Click(object sender, EventArgs e)
        {

            Delete();
        }
        private void Delete()
        {
            try
            {
                for (int i = 0; i < this.gvwNoConfirm.Rows.Count; i++)
                {
                    System.Web.UI.HtmlControls.HtmlInputCheckBox chk = (System.Web.UI.HtmlControls.HtmlInputCheckBox)gvwNoConfirm.Rows[i].FindControl("checkbox1");
                    if (chk.Checked==true)
                    {
                        string HospitalID = CurrentAccount.GetUser().Org.OrgID;
                      //  HZ.Web.WebUtil.Alert(HospitalID);                     
                        int goodsID = Convert.ToInt32(gvwNoConfirm.DataKeys[i].Values[0].ToString());
                        BLL.BLL_HospitalLoginPriceGoods  priceCount= new HZ.DrugTrade.BLL.BLL_HospitalLoginPriceGoods();
                        int count = priceCount.DeletePriceCount(HospitalID, goodsID);
                    }

                }
                SetBind();
            }
            catch (Exception e )
            {

                HZ.Web.WebUtil.Alert("出现"+e+" 错误");
            }
        }

        /// <summary>
        /// 数据提交审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_submit_Click(object sender, EventArgs e)
        {
            
            string sql = string.Format(@"update TB_HospitalLoginPrice set goodsstate=1 where HospitalID='{0}' and 
                        NVL(Price,0)<>0 and NVL(CountProduces,0)<>0  ", CurrentAccount.GetUser().Org.OrgID);
            int check=HZ.Data.DbHelperFactory.Create().ExecuteNonQuery(sql);
            if (check != 0)
            {
                HZ.Web.WebUtil.Alert("数据提交成功！");
            }
            else
            {
                HZ.Web.WebUtil.Alert("数据提交失败！");
            }
            SetBind();
        }
       

    }
}
